
package com.j2eefast.produce.pms.service;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.j2eefast.common.core.page.Query;
import com.j2eefast.common.core.utils.PageUtil;
import com.j2eefast.framework.sys.entity.SysUserEntity;
import com.j2eefast.framework.utils.Constant;
import com.j2eefast.framework.utils.UserUtils;
import com.j2eefast.produce.pms.entity.PmsProjectEntity;
import com.j2eefast.produce.pms.entity.PmsTestEnterListEntity;
import com.j2eefast.produce.pms.entity.PmsTestEntity;
import com.j2eefast.produce.pms.entity.PmsTestProjectEntity;
import com.j2eefast.produce.pms.mapper.PmsTestEnterListMapper;
import com.j2eefast.produce.pms.mapper.PmsTestProjectMapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * <p>检验录入列表</p>
 *
 * @author: summer
 * @date: 2021-05-29 16:47
 * @web: http://www.letukeji.cn
 * @version: 1.0.1
 */
@Service
@Transactional(readOnly = true)
public class PmsTestEnterListService extends ServiceImpl<PmsTestEnterListMapper, PmsTestEnterListEntity> {

	@Resource
	protected PmsTestEnterListMapper pmsTestEnterListMapper;


	/**
	 * 页面展示查询翻页
	 */
	public PageUtil findPage(Map<String, Object> params) {
		String testType = (String) params.get("testType");
		String testName = (String) params.get("testName");
		String type = (String) params.get("type");
		String chargeProject = (String) params.get("chargeProject");
		String quantity = (String) params.get("quantity");
		String batch = (String) params.get("batch");
		String producer = (String) params.get("producer");
		String partUsed = (String) params.get("partUsed");
		String sampleDescription = (String) params.get("samepleDescription");
		String beginTime = (String) params.get("beginTime");
		String endTime = (String) params.get("endTime");
		String testType2 = (String) params.get("testType2");
		String type2 = (String) params.get("type2");
		Page<PmsTestEnterListEntity> page = pmsTestEnterListMapper.findPage(
				new Query<PmsTestEnterListEntity>(params).getPage(),
				StrUtil.nullToDefault(chargeProject,""),
				StrUtil.nullToDefault(testName,""),
				StrUtil.nullToDefault(producer,""),
				StrUtil.nullToDefault(partUsed,""),
				StrUtil.nullToDefault(testType,""),
				StrUtil.nullToDefault(quantity,""),
				StrUtil.nullToDefault(batch,""),
				StrUtil.nullToDefault(type,""),
				StrUtil.nullToDefault(sampleDescription,""),
				StrUtil.nullToDefault(beginTime,""),
				StrUtil.nullToDefault(endTime,""),
				StrUtil.nullToDefault(testType2,""),
				StrUtil.nullToDefault(type2,""),

				(String) params.get(Constant.SQL_FILTER));
		return new PageUtil(page);
	}

	public List<PmsTestEnterListEntity> findList(Map<String, Object> params) {
		String testType = (String) params.get("testType");
		String testName = (String) params.get("testName");
		String producer = (String) params.get("producer");
		String partUsed = (String) params.get("partUsed");
		List<PmsTestEnterListEntity> page = pmsTestEnterListMapper.findList(
				new Query<PmsTestEnterListEntity>(params).getPage(),
				StrUtil.nullToDefault(testType,""),
				StrUtil.nullToDefault(testName,""),
				StrUtil.nullToDefault(producer,""),
				StrUtil.nullToDefault(partUsed,""),
//				StrUtil.nullToDefault(registrationTime,""),
				(String) params.get(Constant.SQL_FILTER));
		return page;
	}


	@Transactional(rollbackFor = Exception.class)
	public boolean deleteByIds(Long[] ids) {

		return pmsTestEnterListMapper.deleteByIds(ids);

	}
	@Transactional(rollbackFor = Exception.class)
	public boolean updateCheck(Long id) {
		Long userId= UserUtils.getUserInfo().getId();

		return pmsTestEnterListMapper.updateCheck(id ,userId);

	}
	public SysUserEntity getSysById(@Param("userId")Long userId){
		return pmsTestEnterListMapper.getSysById(userId);
	}


	public PageUtil selectList(Map<String, Object> params){
		Page<PmsTestEnterListEntity> test=pmsTestEnterListMapper.selectList(new Query<PmsTestEnterListEntity>(params).getPage(),
//				StrUtil.nullToDefault(sampleCode,""),
//				StrUtil.nullToDefault(sampleType,""),
				(String) params.get(Constant.SQL_FILTER));
		//List<PmsTestEnterListEntity>  slist=new ArrayList();
		//List<PmsTestEnterListEntity> slist1 = new ArrayList<PmsTestEnterListEntity>();
//		for (int i = 0; i < test.size() - 1; i++) {
//			for (int j = test.size()-1; j > i; j--) {
//				if (test.get(j).getTestType().equals(test.get(i).getTestType())) {
//					test.remove(j);
//				}
//			}
//		}
		return new PageUtil(test);

	}


}
